package keye.document_manage.main;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Rectangle;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.event.TableModelEvent;

import keye.document_manage.domain.ClassEntityRelation;
import keye.document_manage.domain.ClassEntityRelationWithArchive;
import keye.document_manage.domain.TableInterfaceListView;
import keye.document_manage.entity.Page;
import keye.document_manage.entity.SelectParameters;
import keye.document_manage.gui.CheckDataView;
import keye.document_manage.gui.CheckNode;
import keye.document_manage.gui.MyTable;
import keye.document_manage.gui.MyTableModel;
import keye.document_manage.gui.PagingPanel;
import keye.document_manage.gui.ProgressFrame;
import keye.document_manage.gui.PushDataView;
import keye.document_manage.gui.PushPanel;
import keye.document_manage.gui.RowHeaderTable;
import keye.document_manage.service.IArchivenoFormatService;
import keye.document_manage.service.IClassEntityRelationService;
import keye.document_manage.service.IFilesCheckService;
import keye.document_manage.service.IPushService;
import keye.document_manage.service.ITableInterfaceListViewService;
import keye.document_manage.util.ConvertStringUtil;
import keye.document_manage.util.TreeDemo;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTree;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.UIManager;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.EventObject;
import java.util.List;
import java.util.Map;

public class MainFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public static final ApplicationContext CONTEXT = new ClassPathXmlApplicationContext(
			"classpath:spring-mybatis.xml");
	private JPanel contentPane;
	private JTable table;
	private JMenuItem jit1;
	private JPopupMenu jp = new JPopupMenu();// 鼠标快捷菜单
	private PagingPanel pagingPanel;
	private ITableInterfaceListViewService interfaceListViewService;
	private IClassEntityRelationService classEntityRelationService;
	private IArchivenoFormatService archivenoFormatService;
	private IPushService pushService;
	private IFilesCheckService filesCheckService;
	/**
	 * 最后一次查询条件
	 */
	private List<SelectParameters> selectParas = new ArrayList<SelectParameters>();

	/**
	 * 保存每列所对应数据库表的字段值
	 */
	private String[] fieldNames;

	/**
	 * 记录查询单元格是否有查询条件
	 */
	private int[] valColunm;
	// private List<CheckNode> checkNodes = new Array
	private CheckNode checkNode = null;// 被选择的节点
	private int scalingNumber = 10;// 缩放比例 1/10
	private PushPanel pushPanel;
	private JTree tree;
	private JTable rowHeaderTable;

	private ProgressFrame progressFrameCheck, progressFramePush;

	private JMenuItem jit2;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		//
		EventQueue.invokeLater(() -> {
			try {
				MainFrame frame = new MainFrame();
				frame.setLocationRelativeTo(null);
				UIManager.setLookAndFeel(UIManager
						.getSystemLookAndFeelClassName());
				SwingUtilities.updateComponentTreeUI(frame);
				frame.setBounds(100, 100, 800, 600);
				frame.setExtendedState(Frame.MAXIMIZED_BOTH);
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				frame.setVisible(true);
				System.out.println("启动成功！");

			} catch (Exception e) {
				e.printStackTrace();
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MainFrame() {
		init();
	}

	public void swingWorkerSolve(Object e, int method) {
		System.out.println("method:" + method);
		if (checkNode == null)
			return;
		ClassEntityRelation cer = (ClassEntityRelation) checkNode
				.getUserObject();
		if (cer.geteTableName() == null || "".equals(cer.geteTableName()))
			return;
		new SwingWorker<Integer, Void>() {
			@Override
			protected Integer doInBackground() {
				switch (method) {
				case 1:
					checkSelectTable(checkNode, filesCheckService, selectParas,
							pushPanel.getOsPositionTextField().getText());
					break;
				case 2:
					calculateSize(e);
					break;
				case 3:
					pushData(checkNode, pushService, selectParas, pushPanel
							.getIsCopyFiles().isSelected(), pushPanel
							.getOsPositionTextField().getText(), pushPanel
							.getNewPath().getText(), pushPanel.getPushTitile()
							.getText());
					break;
					// case 4:selectParaChange(e);break;
					// case 5:pageGo(e);break;
					// case 6:selectAndRefresh(new Page());break;
				}
				return 1;
			}
		}.execute();
		new Thread(() -> {
			try {
				pushPanel.getCheckButton().setEnabled(false);
				Thread.sleep(500);
				pushPanel.getCheckButton().setEnabled(true);
			} catch (InterruptedException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}).start();

	}

	/**
	 * 校验
	 * 
	 * @param osPosition
	 * @param selectParas
	 * @param pushService
	 * 
	 * @param e
	 */
	public void checkSelectTable(CheckNode node,
			IFilesCheckService filesCheckService,
			List<SelectParameters> selectParas, String osPosition) {
		System.out.println("checkSelectTable");
		// TODO 校验原文
		ClassEntityRelation cer = (ClassEntityRelation) node.getUserObject();
		// 被选节点没有相关表信息
		if (cer.geteTableName() == null || "".equals(cer.geteTableName()))
			return;

		String logPath = pushPanel.getLogpathTextField().getText();
		if (null == logPath || "".equals(logPath.trim())) {
			JOptionPane.showMessageDialog(null, "请选择校验日志路径！", "日志路径错误",
					JOptionPane.ERROR_MESSAGE);
			return;
		}
		if (pushPanel.getCheckInvalidImage().isSelected()) {
			// InforDialog inforDialog = new
			// InforDialog(node.getUserObject()+" 校验状态", "开始校验......",
			// this, false);
			// new CheckDataView(inforDialog, pushService, selectParas, node,
			// pushPanel.getOsPositionTextField().getText().trim(),
			// logPath.trim()).execute();
			// inforDialog.setVisible(true);

			// 不是叶子节点，即为多层结构，若是叶子节点，则不用关心是否是多层结构
			if (null == progressFrameCheck)
				this.progressFrameCheck = new ProgressFrame();
			showProgressFrame(progressFrameCheck);
			if (node.isLeaf()) {
				new CheckDataView(filesCheckService, progressFrameCheck,
						selectParas, osPosition.trim(), logPath,
						cer.geteTableName()).execute();
			} else {
				node = (CheckNode) node.getFirstLeaf();
				new CheckDataView(filesCheckService, progressFrameCheck,
						selectParas, osPosition.trim(), logPath,
						((ClassEntityRelation) node.getUserObject())
						.geteTableName(), cer.geteTableName())
				.execute();
			}

		}
	}

	/**
	 * 计算原文大小
	 * 
	 * @param e
	 */
	public void calculateSize(Object e) {
		Double size = pushService.calculateSize(selectParas, checkNode);
		if (size == null || size < 0)
			pushPanel.getTotalSize().setText("原文大小：0 KB");
		else
			pushPanel.getTotalSize().setText(
					"原文大小：" + ConvertStringUtil.convertFileSize(size * 1024));
	}

	/**
	 * 发布
	 * 
	 * @param e
	 */
	protected void pushData(CheckNode node, IPushService pushService,
			List<SelectParameters> selectParas, boolean isCopyFiles,
			String osPosition, String newPath, String pushTitile) {
		if (node == null)
			return;
		ClassEntityRelation cer = (ClassEntityRelation) node.getUserObject();
		// 被选节点没有相关表信息
		if (cer.geteTableName() == null || "".equals(cer.geteTableName())) {
			JOptionPane.showMessageDialog(null, "没有选择发布信息！", "发布信息错误",
					JOptionPane.ERROR_MESSAGE);
			return;
		}
		if (null == newPath || null == pushTitile || "".equals(newPath.trim())
				|| "".equals(pushTitile.trim())) {
			JOptionPane.showMessageDialog(null, "请填写发布路径！", "发布路径错误",
					JOptionPane.ERROR_MESSAGE);
			return;
		}
		// TODO 发布,添加进度显示
		if (null == osPosition)
			osPosition = "";
		showProgressFrame(progressFramePush);
		pushPanel.getPushButton().setEnabled(false);
		new PushDataView(progressFramePush, pushService, selectParas, node,
				isCopyFiles, osPosition.trim(), newPath.trim() + File.separator
				+ pushTitile.trim()).execute();
		try {
			Thread.sleep(100);
		} catch (InterruptedException e) {
			
		}
		pushPanel.getPushButton().setEnabled(true);
	}

	public void selectParaChange(Object e) {
		int col = ((TableModelEvent) e).getColumn();
		int row = ((TableModelEvent) e).getFirstRow();
		if (row == 0 && col >= 0) {// 第一行是查询条件
			selectParaChange((TableModel) ((EventObject) e).getSource(), row,
					col);
		}
	}

	/**
	 * 输入的查询条件改变后，进行查询
	 * 
	 * @param model
	 *            改变的表格Model
	 * @param row
	 *            改变的行号
	 * @param col
	 *            改变的列号
	 */
	public void selectParaChange(TableModel model, int row, int col) {
		Object data = model.getValueAt(row, col);
		System.out.println(data);
		if (null == data)
			return;

		if (valColunm[col] == 0) {
			if ("".equals(data.toString().trim()))
				return;
			SelectParameters sp = new SelectParameters();
			// TODO 查询条件多样化
			sp.setName(fieldNames[col]);
			sp.setOpreation("equal");
			sp.setType("string");
			sp.setValue(data);
			selectParas.add(sp);
			valColunm[col] = selectParas.size();
		} else {
			if ("".equals(data.toString().trim())) {
				selectParas.remove(valColunm[col] - 1);
				valColunm[col] = 0;
				for (int i = col + 1; i < valColunm.length; i++) {
					valColunm[i] = valColunm[i] - 1 < 0 ? 0 : valColunm[i] - 1;
				}
			} else {
				selectParas.get(valColunm[col] - 1).setValue(data);
			}
		}
		selectAndRefresh(new Page(), getSelectParas(model));
	}

	public void tableClear(MyTableModel tableModel) {
		tableModel.setRowCount(0);
		tableModel.setColumnCount(0);
	}

	@SuppressWarnings("unchecked")
	public void tableRefreshRows(JTable table, Map<String, Object> map) {
		MyTableModel tableModel = (MyTableModel) table.getModel();
		tableClear(tableModel);

		// cdg 2016-2-19 12:37:18
		MyTableModel rowHeaderModel = (MyTableModel) rowHeaderTable.getModel();
		tableClear(rowHeaderModel);

		if (map == null)
			return;

		/**
		 * 列 ：显示名，字段名，大小
		 */
		List<TableInterfaceListView> listViews = (List<TableInterfaceListView>) map
				.get("listViews");
		int length = listViews.size();
		fieldNames = new String[length];
		int[] widths = new int[length];
		TableInterfaceListView view = null;

		for (int i = 0; i < length; i++) {
			view = listViews.get(i);
			tableModel.addColumn(view.getColumnTitle());
			fieldNames[i] = view.getFieldName();
			try {
				widths[i] = Integer.parseInt(view.getColumnWidth());
				if (widths[i] == -1)
					widths[i] = 200 * scalingNumber;
			} catch (NumberFormatException e) {
				widths[i] = 200 * scalingNumber;
			}
		}
		// 列宽
		TableColumnModel columnModel = table.getColumnModel();
		// TableColumn column = null;
		for (int i = 0; i < widths.length; i++) {
			columnModel.getColumn(i).setPreferredWidth(
					widths[i] / scalingNumber);
		}

		List<Object[]> list = (List<Object[]>) map.get("dataList");
		Object[] objs = (Object[]) map.get("selectValues");
		if (objs == null) {
			tableModel.addRow(new Object[] {});
		} else {
			tableModel.addRow(objs);
		}
		rowHeaderModel.addColumn("");
		rowHeaderModel.addRow(new Object[] { 1 });// cdg 2016-2-19 12:37:18
		for (int i = 0, size = list.size(); i < size; i++) {
			tableModel.addRow(list.get(i));
			rowHeaderModel.addRow(new Object[] { 1 });// cdg 2016-2-19 12:37:18
		}
		// this.selectParas.clear();
		// table.requestFocus();
		// 定位到第一行
		table.getSelectionModel().setSelectionInterval(0, 0);
		Rectangle rect = table.getCellRect(0, 0, true);
		// table.repaint(); 若需要的话
		// table.updateUI();若需要的话
		table.scrollRectToVisible(rect);

	}

	/**
	 * 跳转到某一页
	 */
	public void goPage() {

		try {
			int goNumber = Integer.parseInt(pagingPanel.getGo().getText());
			Page page = pagingPanel.getPage();
			page.setCurrentPage(goNumber);
			// pagingPanel.refresh();
			selectAndRefresh(page, getSelectParas(table.getModel()));
		} catch (NumberFormatException e2) {
			JOptionPane.showMessageDialog(null, "请输入合法数字", "提示",
					JOptionPane.ERROR_MESSAGE);
		}
	}

	/**
	 * 返回查询参数值，并添加参数到selectParas 中
	 * 
	 * @param model
	 * @return
	 */
	public Object[] getSelectParas(TableModel model) {
		Object data = null;
		// 创建参数
		// SelectParameters sp = null;
		int length = model.getColumnCount();
		Object[] selectValues = new Object[length];// 保存查询参数
		for (int i = 0; i < length; i++) {
			data = model.getValueAt(0, i);
			if (null == data
					|| (data instanceof String && "".equals(((String) data)
							.trim()))) {
				continue;
			}
			selectValues[i] = data;
			// sp = new SelectParameters();
			// sp.setName(fieldNames[i]);
			// sp.setOpreation("equal");
			// sp.setType("string");
			// sp.setValue(data);
			// selectParas.add(sp);
			// System.out.println(sp);
		}
		return selectValues;
	}

	/**
	 * 查询并刷新表格
	 * 
	 * @param page
	 */
	public void selectAndRefresh(Page page) {
		selectAndRefresh(page, null);
	}

	/**
	 * 查询并刷新表格
	 * 
	 * @param page
	 * @param selectValues
	 *            查询值
	 */
	public void selectAndRefresh(Page page, Object[] selectValues) {
		selectAndRefresh(page, selectValues, null);
	}

	/**
	 * 查询并刷新表格
	 * 
	 * @param page
	 * @param selectValues
	 * @param where
	 *            where语句后面的查询条件
	 */
	public void selectAndRefresh(Page page, Object[] selectValues, String where) {
		Map<String, Object> map = null;
		if (null == where || "".equals(where))
			map = interfaceListViewService.getList(pagingPanel.getTableName(),
					selectParas, page);
		else
			map = interfaceListViewService.getList(pagingPanel.getTableName(),
					selectParas, page, where);
		pagingPanel.setPage(page);
		if (selectValues != null)
			map.put("selectValues", selectValues);
		else
			map.put("selectValues", new Object[] {});
		tableRefreshRows(table, map);
	}

	public void init() {
		initServices();
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		initComponents();
		initEvents();
	}

	public void initComponents() {
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		JMenu mnNewMenu = new JMenu("窗口");
		menuBar.add(mnNewMenu);

		progressFrameCheck = new ProgressFrame("校验窗口", "正在校验", "校验完成",
				new String[] { "表名", "进度", "操作" }, new String[] { "表名", "用时",
		"操作" });
		progressFramePush = new ProgressFrame("发布窗口", "正在发布", "发布完成",
				new String[] { "状态", "进度", "操作" }, new String[] { "表名", "用时",
		"操作" });

		JMenuItem mntmNewMenuItem = new JMenuItem("校验窗口");
		mnNewMenu.add(mntmNewMenuItem);
		mntmNewMenuItem
		.addActionListener(e -> showProgressFrame(progressFrameCheck));

		JMenuItem mntmNewMenuItem_2 = new JMenuItem("发布窗口");
		mnNewMenu.add(mntmNewMenuItem_2);
		mntmNewMenuItem_2
		.addActionListener(e -> showProgressFrame(progressFramePush));

		JMenu mnNewMenu_1 = new JMenu("菜单2");
		// menuBar.add(mnNewMenu_1);
		JMenuItem mntmNewMenuItem_1 = new JMenuItem("功能1");
		mnNewMenu_1.add(mntmNewMenuItem_1);

		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.CENTER);
		panel.setLayout(new BorderLayout(0, 0));

		JScrollPane scrollPane = new JScrollPane();
		panel.add(scrollPane, BorderLayout.CENTER);

		jit1 = new JMenuItem("校验窗口");
		jit2 = new JMenuItem("发布窗口");
		jp.add(jit1);
		jp.add(jit2);
		// jp.setPreferredSize(new Dimension(80, 20));
		table = new MyTable(new MyTableModel());
		// table.setModel(new MyTableModel());
		// table.getCellRenderer(row, column);
		table.setAutoscrolls(true);
		table.setRowSelectionAllowed(false);// ֻ
		// table.setColumnSelectionAllowed(true);
		table.setCellSelectionEnabled(true);//
		table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);// 列不可随容器组件大小变化自动调整宽度

		scrollPane.setViewportView(table);
		rowHeaderTable = RowHeaderTable.getTable();
		scrollPane.setRowHeaderView(rowHeaderTable);

		// 分页区域
		pagingPanel = new PagingPanel();
		panel.add(pagingPanel, BorderLayout.SOUTH);

		tree = TreeDemo.createDefaultTree(classEntityRelationService,
				archivenoFormatService);
		JScrollPane jsp = new JScrollPane(tree);
		jsp.setPreferredSize(new Dimension(200, 0));
		jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		contentPane.add(jsp, BorderLayout.WEST);

		pushPanel = new PushPanel();
		pushPanel.setPreferredSize(new Dimension(0, 150));
		contentPane.add(pushPanel, BorderLayout.SOUTH);
	}

	private void showProgressFrame(ProgressFrame progressFrame) {
		if (!progressFrame.isVisible()) {
			progressFrame.setVisible(true);
		}
		if (progressFrame.getState() == JFrame.ICONIFIED) {
			progressFrame.setState(NORMAL);
		}
		if (!progressFrame.isActive()) {
			progressFrame.setAlwaysOnTop(true);
			progressFrame.setAlwaysOnTop(false);
		}
	}

	/**
	 * 跳转页面，上一页，下一页
	 * 
	 * @param e
	 */
	public void pageGo(ActionEvent e) {
		System.out.println(e.getSource());
		System.out.println(e.getActionCommand());
		if (pagingPanel.getPage().getTotalNumber() == 0)
			return;
		switch (e.getActionCommand()) {
		case "next":
			selectAndRefresh(pagingPanel.getPage().nextPage(),
					getSelectParas(table.getModel()));
			break;
		case "previous":
			selectAndRefresh(pagingPanel.getPage().previousPage(),
					getSelectParas(table.getModel()));
			break;
		case "go":
			goPage();
			break;
		}
	}

	public void initEvents() {

		jit1.addActionListener(e -> showProgressFrame(progressFrameCheck));
		jit2.addActionListener(e -> showProgressFrame(progressFramePush));

		table.addMouseListener(new MouseAdapter() {// 添加鼠标监听器
			public void mouseReleased(MouseEvent e) {
				if (e.getModifiers() == MouseEvent.BUTTON3_MASK) {// 鼠标点击为 右键时显示
					jp.show(table, e.getX(), e.getY()); // 快捷菜单
				}
			}
		});
		table.getModel().addTableModelListener(e -> {
			int col = e.getColumn();
			int row = e.getFirstRow();
			if (row == 0 && col >= 0) {// 第一行是查询条件
				selectParaChange((TableModel) e.getSource(), row, col);
			}
		});

		// pagingPanel.getNextB().addActionListener( e ->
		// swingWorkerSolve(e,5));
		// pagingPanel.getPreviousB().addActionListener( e ->
		// swingWorkerSolve(e,5));
		// pagingPanel.getGoButton().addActionListener( e ->
		// swingWorkerSolve(e,5));

		pagingPanel.getNextB().addActionListener(e -> pageGo(e));
		pagingPanel.getPreviousB().addActionListener(e -> pageGo(e));
		pagingPanel.getGoButton().addActionListener(e -> pageGo(e));
		pagingPanel.getGoValue().addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_ENTER) {
					pageGo(new ActionEvent(e, e.getID(), "go"));
				}
			}
		});

		// tree.addMouseListener(new MouseAdapter() {
		// public void mousePressed(MouseEvent e) {
		// // 得到被选的节点
		// int x = e.getX();
		// int y = e.getY();
		// int row = tree.getRowForLocation(x, y);
		// TreePath path = tree.getPathForRow(row);
		// // 判断是否单击了节点
		// if (path != null) {
		// // 取得被单击的节点
		// CheckNode node = (CheckNode) path.getLastPathComponent();
		// boolean isSelected = !(node.isSelected());
		// // 设置被单击的节点CheckBox,使其状态与原来状态相反
		// node.setSelected(isSelected);
		// // 刷新树(这步是必须的,否则将看不到上面所有设置的效果);
		// ((DefaultTreeModel) tree.getModel()).nodeChanged(node);
		// tree.revalidate();
		// tree.repaint();
		// //tree.updateUI();
		// }
		// }
		// });
		tree.addTreeSelectionListener(e -> {
			CheckNode node = (CheckNode) tree.getLastSelectedPathComponent();

			if (node == null)
				return;
			Object object = node.getUserObject();
			ClassEntityRelation entity = (ClassEntityRelation) object;

			pagingPanel.getGo().setText("");
			selectParas.clear();
			String tableName = entity.geteTableName();
			if (tableName != null && !"".equals(tableName.trim())) {
				pagingPanel.setTableName(tableName);
				// swingWorkerSolve(e,6);
				selectAndRefresh(new Page());
				valColunm = new int[fieldNames.length];
				checkNode = node;
			} else {
				tableClear((MyTableModel) table.getModel());
				tableClear((MyTableModel) rowHeaderTable.getModel());// 2016-2-19
				// 15:28:09
				pagingPanel.setPage(new Page());
				checkNode = null;
			}
			// 显示校验规则
			setSegmentRule(((ClassEntityRelationWithArchive) object)
					.getFormat());
		});

		pushPanel.getCheckButton().addActionListener(
				e -> swingWorkerSolve(e, 1));// 校验
		// pushPanel.getIsCopyFiles().addActionListener(e-> swingWorkerSolve( e,
		// 2) );
		pushPanel.getCalculateSizeBtn().addActionListener(
				e -> swingWorkerSolve(e, 2));
		pushPanel.getPushButton()
		.addActionListener(e -> swingWorkerSolve(e, 3));// 发布

		pushPanel.getDiySelectBtn().addActionListener(
				e -> selectAndRefresh(new Page(),
						getSelectParas(table.getModel()), pushPanel
						.getTxtFilingyearsqlWhere().getText().trim()));// 自定义查询
	}

	public void initServices() {
		interfaceListViewService = (ITableInterfaceListViewService) MainFrame.CONTEXT
				.getBean("interfaceListViewService");
		classEntityRelationService = (IClassEntityRelationService) MainFrame.CONTEXT
				.getBean("classEntityService");
		archivenoFormatService = (IArchivenoFormatService) MainFrame.CONTEXT
				.getBean("archivenoFormatService");
		pushService = (IPushService) MainFrame.CONTEXT.getBean("pushService");
		filesCheckService = (IFilesCheckService) MainFrame.CONTEXT
				.getBean("filesCheckService");
	}

	/**
	 * 显示档号格式
	 * 
	 * @param nameAndFileds
	 */
	public void setSegmentRule(String[][] nameAndFileds) {
		if (nameAndFileds != null)
			pushPanel.getRuleTextField().setText(nameAndFileds[0][0]);
		else
			pushPanel.getRuleTextField().setText("");
	}

}
